package com.witdata.controller.docker;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.docker.Image;
import com.witdata.common.domain.docker.InstanceImage;
import com.witdata.framework.service.docker.DockerImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/docker/image")
@RequiredArgsConstructor
public class ImageController {
    private final DockerImageService dockerImageService;

    @GetMapping("/list")
    public Result<List<Image>> getImageList(@RequestParam("instanceId")  Long instanceId) {
        List<Image> imageList = dockerImageService.getImageList(instanceId);
        return Result.ok(Status.SUCCESS, imageList);
    }

    @PostMapping("/remove")
    public Result<String> removeImage(@RequestBody InstanceImage instanceImage) {
        dockerImageService.removeImage(instanceImage);
        return Result.ok(Status.REMOVESUCCESS);
    }

    @PostMapping("/pull")
    public Result<String> pullImage(@RequestBody InstanceImage instanceImage) {
        dockerImageService.pullImage(instanceImage);
        return Result.ok(Status.SUCCESS);
    }

}
